/**
 * 
 */
package leetCode;

/**
 * @author zhong
 *
 */
public class RotateDigits {
	public int rotatedDigits(int N) {
		int good = 0;
		int x = 1;
		while (x <= N) {
			if (isGood(x)) {
				good++;
			}
			x++;
		}
		return good;
	}

	private boolean isGood(int x) {
		boolean good = false;
		while (x > 0) {
			int last = x % 10;
			if (last == 2 || last == 5 || last == 6 || last == 9) {
				good = true;// 存在不一样的
			} else if (last == 3 || last == 4 || last == 7) {// 不能旋转
				return false;
			}
			x /= 10;
		}
		return good;
	}

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		System.out.println(new RotateDigits().rotatedDigits(12));
	}

}
